home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
GDK
/
Grid.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
4KB
|
156 lines
class GDK.Grid extends Array
{
var _overflow = true;
var defaultValue = null;
var _width = 0;
var _height = 0;
var _area = 0;
var repeatX = true;
var repeatY = true;
var _mode = 0;
function Grid(w, h, defaultValue)
{
super();
this.setSize(w != null ? w : 0,h != null ? h : 0,true);
if(defaultValue != null)
{
this.defaultValue = defaultValue;
}
}
function get width()
{
return this._width;
}
function set width(x)
{
this.setSize(x,this._height);
}
function get height()
{
return this._height;
}
function set height(x)
{
this.setSize(this._width,x);
}
function setSize(w, h, noRebuild)
{
if(w == this._width && h == this._height)
{
return false;
}
if(h != null && h > 0)
{
this._overflow = false;
this.setCell = this.setCell2D_Fixed;
this.getCell = this.getCell2D_Fixed;
this._area = w * h;
if(!noRebuild && this._mode == 0)
{
}
this._mode = 3;
}
else
{
this._overflow = true;
if(x <= 0)
{
this.setCell = this.setCell2D;
this.getCell = this.getCell2D;
if(!noRebuild && this._mode == 0)
{
}
this._mode = 1;
}
else
{
delete this.setCell;
delete this.getCell;
if(!noRebuild && this._mode != 0)
{
}
this._mode = 0;
}
}
this._width = w > 0 ? w : 0;
this._height = h > 0 ? h : 0;
return true;
}
function setCell(w, v)
{
this[w] = v;
}
function __resolve(v)
{
return this.defaultValue;
}
function getCell(w)
{
return (value = this[w]) == null ? this.defaultValue : value;
}
function setCell2D(w, h, val)
{
if(h != null && h < 0)
{
h = Math.floor(w / this._width);
}
else
{
w += h * this._width;
}
if(h >= this._height)
{
this._height = h + 1;
}
this[w] = val;
}
function getCell2D(w, h)
{
if(h != null)
{
return this[w + (h >= 0 ? h : this._height + h % this._height) * this._width];
}
return this[w] % this._width;
}
function setCell2D_Fixed(w, h, val)
{
var _loc3_ = undefined;
var _loc2_ = undefined;
this[((_loc3_ = w % this._width) >= 0 ? _loc3_ : this._width + _loc3_) + ((_loc2_ = h % this._height) >= 0 ? _loc2_ : this._height + _loc2_) * this._width] = val;
}
function getCell2D_Fixed(x, y)
{
if(!this.repeatX && !(x > -1 && x < this._width) || !this.repeatY && !(y > -1 && y < this._height))
{
return this.defaultValue;
}
var _loc3_ = undefined;
var _loc2_ = undefined;
return this[((_loc3_ = x % this._width) >= 0 ? _loc3_ : this._width + _loc3_) + ((_loc2_ = y % this._height) >= 0 ? _loc2_ : this._height + _loc2_) * this._width];
}
function toString()
{
var _loc3_ = "";
var _loc2_ = this.length;
_loc2_ = this.length;
while((_loc2_ = _loc2_ - 1) > 0)
{
_loc3_ = this[_loc2_] + _loc3_;
_loc3_ = (_loc2_ % this.__get__width() != 0 ? "," : ",\n") + _loc3_;
}
if(this.length > 0)
{
_loc3_ = this[0] + _loc3_;
}
return _loc3_;
}
function copyFromArray(a)
{
var _loc2_ = a.length;
while((_loc2_ = _loc2_ - 1) > -1)
{
this[_loc2_] = a[_loc2_];
}
}
}